<?php
/**
 * Created by PhpStorm.
 * User: YH
 * Date: 2019/5/13
 * Time: 17:44
 */


header("Access-Control-Allow-Origin:*");
header("Content-Type:application/json;charset=utf-8");
include "dbHelper.php";

session_start();//开启session

if ($_SERVER["REQUEST_METHOD"]=="POST"){
    sleep(1);
    if (isset($_REQUEST["uname"])&&isset($_REQUEST["upwd"])){
        $UNAME=$_POST["uname"];
        $UPWD=$_POST["upwd"];


        $sql="SELECT `u_id`,`u_name`,`u_email` FROM `userinfo` WHERE u_name='".$UNAME."' AND u_pwd='".$UPWD."'";

        $result=dbHelper($sql);



       if ($result->num_rows>=1){
       	
           $userInfoArr=$result->fetch_assoc();
           
            print_r(json_encode(Array("msg"=>"登录成功","status"=>1,"data"=>$userInfoArr)));

            //登录成功之后,会响应返回一个PHPSESSIONID
            $_SESSION["userInfo"]=$userInfoArr;


        }else{
            print_r(json_encode(Array("msg"=>"登录失败","status"=>0)));
        }

    }
}else{
    print_r(json_encode(Array("msg"=>"不支持get请求","status"=>-1)));
}


